import  React, {useState} from 'react';
import { SearchHistory } from '@nutui/nutui-biz';
import App from './search1'


export default function Search() {
    const [recentSearchData, setRecentSearchData] = useState(JSON.parse(localStorage.getItem('recentSearchData')) || [])
    const searchDiscoverData = [
      {
        key: '小米手环',
        url: ''
      },
      {
        key: '对讲机',
        url: ''
      }
    ]
  
    const handleClick = (val) => { 
      if(val.trim() === '') return
  
      let arr = JSON.parse(localStorage.getItem('recentSearchData')) || [];
      let len = arr.filter((item) => item.key === val).length
  
      if(len > 0) {
        arr = arr.filter((item) => item.key !== val)
      }
  
      arr.unshift({
        key: val,
        url: ''
      })
  
      localStorage.setItem('recentSearchData', 
        JSON.stringify(arr)
      )
      setRecentSearchData(arr)
    }
  
    const handleDelete = () => {
      localStorage.removeItem('recentSearchData')
      setRecentSearchData([])
    }
  return (
    <div>
         {/* <SearchHistory 
            rightOutIcon={<div style={{background: '#e93b3d', padding: '6px', borderRadius: '4px', color: '#fff', fontSize: '14px'}}>搜索</div>}
            onClickSearchButton={handleClick}
            onDelete={handleDelete}
            recentSearchData={recentSearchData} 
            searchDiscoverData={searchDiscoverData} 
        /> */}
        <App></App>
    </div>
  )
}
